<?php
namespace Home\Controller;
use Home\Common\Common;
class SyrecordinfoController extends Common{
    /**
     * 查询
     */
    public function index(){
        $syrecordinfo=M('sy_recordinfo');
        if(!empty($_POST['tj'])){
            $where= 'state=1 and `dn_time` like "%'.$_POST['tj'].'%"';//得到条件
        }else{
            $where='state=1';
        }
        $count=$syrecordinfo->where($where)->count();//总条数
        $page=new \Think\Page($count,8);//实例化分类页
        $show=$page->show();//输出分页
        $list=$syrecordinfo->where($where)->limit($page->firstRow.','.$page->listRows)->select();//取出当前页数据

        $this->assign('listid',M('staffinfo')->select());//输出发布人表
//        $this->assign('sylist',M('systeminto')->select());//输出类型

        $this->assign('count',$count);//将总条数输出到页面
        $this->assign('show',$show);//将分页输出到页面
        $this->assign('list',$list);//将数据输出到页面
        $this->display();
    }
    /**
     * 回收站
     */
    public function Recycle_bin(){
        $syrecordinfo=M('sy_recordinfo');
        if(!empty($_POST['tj'])){
            $where= 'state=0 and `dn_time` like "%'.$_POST['tj'].'%"';//得到条件
        }else{
            $where='state=0';
        }
        $count=$syrecordinfo->where($where)->count();//总条数
        $page=new \Think\Page($count,8);//实例化分类页
        $show=$page->show();//输出分页
        $list=$syrecordinfo->where($where)->limit($page->firstRow.','.$page->listRows)->select();//取出当前页数据

        $this->assign('listid',M('staffinfo')->select());//输出发布人表
//        $this->assign('sylist',M('systeminto')->select());//输出类型

        $this->assign('count',$count);//将总条数输出到页面
        $this->assign('show',$show);//将分页输出到页面
        $this->assign('list',$list);//将数据输出到页面
        $this->display();
    }
    /**
     * 恢复数据
     */
    public function Recycle_add(){
        if(empty($_POST['id'])){
            $this->error('参数错误!');
        }
        $syrecordinfo=M('sy_recordinfo');
        foreach ($_POST['id'] as $value){
            $syrecordinfo->where('dn_id='.$value)->save(array('state'=>1));
        }
        $this->success('恢复成功！',U('Recycle_bin'));
    }
    /**
     * 添加
     */
    public function add(){
        if(empty($_POST['submit'])){
            $this->assign('sylist',M('systeminto')->select());
            $this->assign('stlist',M('staffinfo')->select());
            $this->display();
        }else{
            if(is_null($_POST['dn_result'])||empty($_POST['dn_reason'])||empty($_POST['sy_id'])||empty($_POST['dn_staffid'])){
                $this->error('请完善数据！');
            }

            $systeminto=M('systeminto');
            $syrecordinfo=M('sy_recordinfo');

            $dnt=$systeminto->where('sy_id='.$_POST['sy_id'])->find();//查询制度表

            $_POST['dn_type']=$dnt['sy_type'];
            $_POST['amount']=$dnt['amount'];

            $_POST['dn_time']=date("Y-m-d H:i:s");
            $_POST['person']=$_SESSION['aid'];
            $_POST['state']=1;
            $syrecordinfo->add($_POST);
            $this->success('添加成功！',U('index'));
        }
    }

    /**
     * 删除（隐藏）单条
     */
    public function upd(){
        if(empty($_GET['id'])){
            $this->error('参数错误！');
        }
        $state=0;
        $zd='state';
        $ts='删除成功！';
        $syrecordinfo=M('sy_recordinfo');
//        if(!is_null($_GET['state'])){//判断state 不为0和空
//            $state=1;
//            $zd='dn_result';
//            $ts='修改成功';
//        }
        $syrecordinfo->where('dn_id='.$_GET['id'])->save(array($zd=>$state));
        $this->success($ts,U('index'));

    }
    /**
     *删除全部 （隐藏）
     */
    public function del_all(){
        if(empty($_POST['id'])){
            $this->error('参数错误');
        }
        $sy_recordinfo=M('sy_recordinfo');
        foreach ($_POST['id'] as $value){
            $sy_recordinfo->where('dn_id='.$value)->save(array('state'=>0));
        }
        $this->success('删除成功！',U('index'));
    }
}